import java.io.IOException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.util.Calendar;

public class Longtelserver {
    public String billtest(final String string1, final String string2) {
        Longtelserver ls = new Longtelserver();
        Calendar st = java.util.Calendar.getInstance();
        Calendar et = java.util.Calendar.getInstance();
        String[] s1Arr = string1.split("[- , :]");
        String[] s2Arr = string2.split("[- , :]");
        int minsmonth = 1;
        final int maxsmonth = 12;
        int minhour = 0;
        final int maxhour = 24;
        int minsm = 0;
        final int maxsm = 60;
        int maxspan = 0; //当从判断时长的函数出来返回为0则表示超过30小时了
        final int n = 3;

        while (true) {
            int sy = Integer.parseInt(s1Arr[0]);
            int smonth = Integer.parseInt(s1Arr[1]);
            int sd = Integer.parseInt(s1Arr[2]);
            int sh = Integer.parseInt(s1Arr[n]);
            int sm = Integer.parseInt(s1Arr[n + 1]);
            int ss = Integer.parseInt(s1Arr[n + 2]);
            System.out.println(sy + "-" + smonth + "-" + sd + " " + sh + ":" + sm + ":" + ss);

            int ey = Integer.parseInt(s2Arr[0]);
            int emonth = Integer.parseInt(s2Arr[1]);
            int ed = Integer.parseInt(s2Arr[2]);
            int eh = Integer.parseInt(s2Arr[n]);
            int em = Integer.parseInt(s2Arr[n + 1]);
            int es = Integer.parseInt(s2Arr[n + 2]);
            System.out.println(ey + "-" + emonth + "-" + ed + " " + eh + ":" + em + ":" + es);

            DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (smonth < minsmonth || smonth > maxsmonth || emonth < minsmonth || emonth > maxsmonth) {
                return ("输入月份错误，范围为1<=months<=12，请重新输入月份！");
            } else if (sh < minhour || sh >= maxhour || eh < minhour || eh >= maxhour) {
                return ("输入小时错误！");

            } else if (sm < minsm || sm > maxsm || em < minsm || em > maxsm) {
                return ("输入分钟错误！");

            } else if (ss < minsm || ss > maxsm || es < minsm || es > maxsm) {
                return ("输入秒数错误！");
            } else {
                try {
                    st.setTime(df.parse(sy + "-" + smonth + "-" + sd + " " + sh + ":" + sm + ":" + ss));
                    et.setTime(df.parse(ey + "-" + emonth + "-" + ed + " " + eh + ":" + em + ":" + es));
                } catch (java.text.ParseException e) {
                    return ("日期格式输入不正确,程序终止！");
                }
                break;
            }
        }
        if (st.compareTo(et) > minsm) {
            return ("开始通话时间大于结束通话时间，输入有误，本次计费作废！");
        }
        //输入时间合法，则进行计算
        Judgedate judgedate = new Judgedate(st, et);
        int rs = judgedate.judge(); //将通话日期传入计算时长（考虑了时制、秒数，返回通话时长）
        if (rs == maxspan) {
            return ("通话时间超过30小时，输入有误，本次计费作废！");
        }
        final int totalminiute = rs; //按照电话账单最终计算出来的通话时长
        DecimalFormat df = new DecimalFormat("0.000"); //设置double类型小数点后位数格式
        Caculatefee cf = new Caculatefee(); //计算一次通话的话费
        double cost = cf.calculate(totalminiute);
        return ("本次通话的话费为:" + df.format(cost) + "美元");
    }

    public static void main(final String[] args) throws IOException {

    }
}
